Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+8.8k Golang : Accept any number of function arguments with three dots(...)
+21.5k Golang : How to read float value from standard input ?
+9k Golang : automatically figure out array length(size) with three dots
+36.5k Golang : Validate IP address
+12.3k Golang : Get month name from date example
+15k Golang : Search folders for file recursively with wildcard support
+6.1k nginx : force all pages to be SSL
+10.9k Golang : Sieve of Eratosthenes algorithm
+80.6k Golang : How to return HTTP status code?
+51.9k Golang : How to get time in milliseconds?